package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.RecZmPaperManagement;
import com.ruoyi.system.service.IRecZmPaperManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 专门档案 案卷管理Controller
 *
 * @author yzf
 * @date 2022-06-03
 */
@RestController
@RequestMapping("/system/ZmPaperManagement")
public class RecZmPaperManagementController extends BaseController {
    @Autowired
    private IRecZmPaperManagementService recZmPaperManagementService;

    /**
     * 查询专门档案 案卷管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:RecZmPaperManagement:list')")
    @GetMapping("/list")
    public TableDataInfo list(RecZmPaperManagement recZmPaperManagement) {
        startPage();
        List<RecZmPaperManagement> list = recZmPaperManagementService.selectRecZmPaperManagementList(recZmPaperManagement);
        return getDataTable(list);
    }

    /****
     *根据题名查询案卷
     * @param recZmPaperManagement
     * @return
     */
    @GetMapping("/listByName")
    public AjaxResult listByName(RecZmPaperManagement recZmPaperManagement) {
        List<Map<String, Object>> list = recZmPaperManagementService.selectlistByName(recZmPaperManagement);
        return AjaxResult.success(list);
    }

    /**
     * 导出专门档案 案卷管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:RecZmPaperManagement:export')")
    @Log(title = "专门档案 案卷管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RecZmPaperManagement recZmPaperManagement) {
        List<RecZmPaperManagement> list = recZmPaperManagementService.selectRecZmPaperManagementList(recZmPaperManagement);
        ExcelUtil<RecZmPaperManagement> util = new ExcelUtil<RecZmPaperManagement>(RecZmPaperManagement.class);
        util.exportExcel(response, list, "专门档案 案卷管理数据");
    }

    /**
     * 获取专门档案 案卷管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:RecZmPaperManagement:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(recZmPaperManagementService.selectRecZmPaperManagementById(id));
    }

    /**
     * 新增专门档案 案卷管理
     */
    @PreAuthorize("@ss.hasPermi('system:RecZmPaperManagement:add')")
    @Log(title = "专门档案 案卷管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RecZmPaperManagement recZmPaperManagement) {
        return toAjax(recZmPaperManagementService.insertRecZmPaperManagement(recZmPaperManagement));
    }

    /**
     * 修改专门档案 案卷管理
     */
    @PreAuthorize("@ss.hasPermi('system:RecZmPaperManagement:edit')")
    @Log(title = "专门档案 案卷管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RecZmPaperManagement recZmPaperManagement) {
        return toAjax(recZmPaperManagementService.updateRecZmPaperManagement(recZmPaperManagement));
    }

    /**
     * 案卷归档拒绝
     */
    @Log(title = "案卷归档拒绝", businessType = BusinessType.UPDATE)
    @PutMapping("/reject/{ids}")
    public AjaxResult updateArchivesReject(@PathVariable String[] ids) {
        return toAjax(recZmPaperManagementService.updateArchivesReject(ids));
    }

    /**
     * 删除专门档案 案卷管理
     */
    @PreAuthorize("@ss.hasPermi('system:RecZmPaperManagement:remove')")
    @Log(title = "专门档案 案卷管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(recZmPaperManagementService.deleteRecZmPaperManagementByIds(ids));
    }

    /**
     * 案卷归档申请
     */
    @Log(title = "案卷归档申请", businessType = BusinessType.UPDATE)
    @PutMapping("/apply/{ids}")
    public AjaxResult updateArchivesApply(@PathVariable String[] ids) {
        return toAjax(recZmPaperManagementService.updateArchivesApplyByIds(ids));
    }

    /**
     * 案卷归档通过
     */
    @Log(title = "案卷归档通过", businessType = BusinessType.UPDATE)
    @PutMapping("/approve/{ids}")
    public AjaxResult updateArchivesApprove(@PathVariable String[] ids) {
        return toAjax(recZmPaperManagementService.updateArchivesApprove(ids));
    }

    /**
     * 文件导入
     */
    @Log(title = "文件导入", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('system:ZmPaperManagement:importData')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception {
        ExcelUtil<RecZmPaperManagement> util = new ExcelUtil<RecZmPaperManagement>(RecZmPaperManagement.class);
        List<RecZmPaperManagement> fileList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = recZmPaperManagementService.importFile(fileList, operName);
        return AjaxResult.success(message);
    }

    /**
     * 导入模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil<RecZmPaperManagement> util = new ExcelUtil<RecZmPaperManagement>(RecZmPaperManagement.class);
        util.importTemplateExcel(response, "项目工程数据");
    }
}
